'''
Author: luqinghua
Date: 2025-03-23 18:08:57
LastEditors: luqinghua
LastEditTime: 2025-03-23 20:29:42
FilePath: \pywebview-vue\python\jsApi.py
Description: 
'''
import webview

# 定义测试对象
def get_device_info():
    return {"version": "V1.0.0", "description": "pywebview集成Vue示例", "environment": "pywebview+vue+ts","others":""}

#定义与前端交互的api   
class Api:
    def __init__(self) -> None:
        self._window = None

    def set_window(self, window):
        self._window = window
    # 获取消息    
    def getMessage(self):
        return get_device_info()
    # 接收前端提交的数据
    def saveMessage(self, data):
        return f"python接收到数据: {data}"
    # 打开新窗口
    def open_new_window(self, data):
        window = webview.create_window(
            title=data.get('title'),
            url=data.get('url'),
            width=1000,
            height=700,
            # confirm_close=True,  # 关闭时提示
        )